package by.grsu.crs.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class SignUpStepOneForm extends ActionForm {
	private static final long serialVersionUID = -4035836096261336952L;
	
	private String email;
    private String password;
    private String passwordRetry;
    
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        
        if (email == null || email.length() < 1) {
            errors.add("email", new ActionMessage("error.email.required"));
        }
        
        if (password == null || password.length() < 1) {
            errors.add("password", new ActionMessage("error.password.required"));
        }
        
        if (passwordRetry == null || passwordRetry.length() < 1) {
            errors.add("passwordRetry", new ActionMessage("error.passwordRetry.required"));
        }
        
        if (password.length() < 8 || password.length() > 16) {
            errors.add("password", new ActionMessage("error.password.length"));
            return errors;
        }
        
        if (passwordRetry.length() < 8 || passwordRetry.length() > 16) {
            errors.add("passwordRetry", new ActionMessage("error.password.length"));
            return errors;
        }
        
        if (!passwordRetry.equals(password)) {
            errors.add("passwordRetry", new ActionMessage("error.passwordRetry.doesnt-match"));
        }
        
        return errors;
    }

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordRetry() {
		return passwordRetry;
	}

	public void setPasswordRetry(String passwordRetry) {
		this.passwordRetry = passwordRetry;
	}
   
}
